package com.brspace.qualitycontrol.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.brspace.qualitycontrol.entity.MeetNotice;
import com.brspace.qualitycontrol.entity.vo.NoticeVo;
import com.brspace.qualitycontrol.mapper.MeetNoticeMapper;
import com.brspace.qualitycontrol.service.MeetNoticeService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.brspace.qualitycontrol.utils.EmptyUtil;
import com.brspace.qualitycontrol.utils.R;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;
import java.util.Objects;

/**
 * <p>
 * 会议通知 服务实现类
 * </p>
 *
 * @author ${author}
 * @since 2021-04-02
 */
@Service
public class MeetNoticeServiceImpl extends ServiceImpl<MeetNoticeMapper, MeetNotice> implements MeetNoticeService {
    @Resource
    private MeetNoticeMapper meetNoticeMapper;

    /**
     * 添加会议通知
     * @param meetNotice
     * @return
     */
    @Override
    public R addMeetNot(MeetNotice meetNotice) {
        if (EmptyUtil.isEmpty(meetNotice.getMeetingName())) {
            throw  new SecurityException("会议名称为空");
        }
        if (EmptyUtil.isEmpty(meetNotice.getMeetingPeople())) {
            throw  new SecurityException("人员为空");
        }
        if (EmptyUtil.isEmpty(meetNotice.getMeetingData())) {
            throw  new SecurityException("会议日期为空");
        }
        if (EmptyUtil.isEmpty(meetNotice.getMeetingTime())) {
            throw  new SecurityException("会议时间为空");
        }
        if (EmptyUtil.isEmpty(meetNotice.getMeetingAdress())) {
            throw  new SecurityException("会议地点为空");
        }
        if (meetNoticeMapper.insert(meetNotice)>0) {
            return R.ok().message("添加成功！");
        }
        return R.error().message("添加失败！");
    }

    @Override
    public IPage<MeetNotice> selectPage(Page<MeetNotice> pageParam, Object o) {
        return baseMapper.selectPage(pageParam,null);
    }

    //查询指定日期的会议消息
    @Override
    public List<NoticeVo> getDayList(Date noticeDate) {
        return meetNoticeMapper.getDayList(noticeDate);
    }

    //获取今天之后有会议的日期
    @Override
    public List<String> getNoticeAfter() {
        return meetNoticeMapper.getNoticeAfter();
    }
}
